﻿Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Workflow.ComponentModel.Design

Namespace System.Workflow.ComponentModel
    <SRDescription("CompensatableTransactionalContextActivityDescription"), Designer(GetType(CompensatableTransactionScopeActivityDesigner), GetType(IDesigner)), ToolboxBitmap(GetType(CompensatableTransactionScopeActivity), "Resources.Sequence.png"), PersistOnClose, SupportsTransaction, ToolboxItem(GetType(ActivityToolboxItem))> _
    Public NotInheritable Class CompensatableTransactionScopeActivity
        Inherits CompositeActivity
        Implements IActivityEventListener([Of] ActivityExecutionStatusChangedEventArgs), ICompensatableActivity
        ' Methods
        Public Sub New()
            MyBase.SetValueBase(CompensatableTransactionScopeActivity.TransactionOptionsProperty, New WorkflowTransactionOptions)
        End Sub

        Public Sub New(ByVal name As String)
            MyBase.New(name)
            MyBase.SetValueBase(CompensatableTransactionScopeActivity.TransactionOptionsProperty, New WorkflowTransactionOptions)
        End Sub

        Protected Friend Overrides Function Cancel(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            Return SequenceHelper.Cancel(Me, executionContext)
        End Function

        Protected Friend Overrides Function Execute(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            Return SequenceHelper.Execute(Me, executionContext)
        End Function

        Protected Friend Overrides Sub OnActivityChangeRemove(ByVal executionContext As ActivityExecutionContext, ByVal removedActivity As Activity)
            SequenceHelper.OnActivityChangeRemove(Me, executionContext, removedActivity)
        End Sub

        Protected Friend Overrides Sub OnWorkflowChangesCompleted(ByVal executionContext As ActivityExecutionContext)
            SequenceHelper.OnWorkflowChangesCompleted(Me, executionContext)
        End Sub

        Private Sub System.Workflow.ComponentModel.IActivityEventListener<System.Workflow.ComponentModel.ActivityExecutionStatusChangedEventArgs>.OnEvent(ByVal sender As Object, ByVal e As ActivityExecutionStatusChangedEventArgs) Implements IActivityEventListener([Of] ActivityExecutionStatusChangedEventArgs).OnEvent
            SequenceHelper.OnEvent(Me, sender, e)
        End Sub

        Private Function System.Workflow.ComponentModel.ICompensatableActivity.Compensate(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus Implements ICompensatableActivity.Compensate
            Return ActivityExecutionStatus.Closed
        End Function


        ' Properties
        <DesignerSerializationVisibility(DesignerSerializationVisibility.Content), [ReadOnly](True), SRDescription("TransactionDesc"), MergableProperty(False)> _
        Public Property TransactionOptions As WorkflowTransactionOptions
            Get
                Return DirectCast(MyBase.GetValue(CompensatableTransactionScopeActivity.TransactionOptionsProperty), WorkflowTransactionOptions)
            End Get
            Set(ByVal value As WorkflowTransactionOptions)
                MyBase.SetValue(CompensatableTransactionScopeActivity.TransactionOptionsProperty, value)
            End Set
        End Property


        ' Fields
        Friend Shared ReadOnly TransactionOptionsProperty As DependencyProperty = DependencyProperty.Register("TransactionOptions", GetType(WorkflowTransactionOptions), GetType(CompensatableTransactionScopeActivity), New PropertyMetadata(DependencyPropertyOptions.Metadata, New Attribute() { New DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content) }))
    End Class
End Namespace

